// -----------------------------------------------------------------------
//  <copyright file="GetDictionaryTypePageQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2025 66SOFT. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-10-17 01:10</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization;
using DaprPlus.DataDicts.Domain.Dtos;
using DaprPlus.DataDicts.Domain.Entities;
using DaprPlus.MediatR;

using OSharp.Filter;


namespace DaprPlus.DataDicts.Application.Queries;

[AuthConfig(typeof(DictionaryType), ResourceAccessType.RoleLimit, "GetPage")]
public class GetDictionaryTypePageQuery : PageQuery<PageResult<DictionaryTypeOutDto>>
{ }

public class GetDictionaryTypePageQueryHandler(IServiceProvider provider)
    : IRequestHandler<GetDictionaryTypePageQuery, PageResult<DictionaryTypeOutDto>>
{
    public async Task<PageResult<DictionaryTypeOutDto>> Handle(GetDictionaryTypePageQuery request,
        CancellationToken cancellationToken)
    {
        var logger = provider.GetLogger<GetDictionaryTypePageQueryHandler>();
        var queryRepository = provider.GetQueryRepository<DictionaryType>();
        var spec = new PageQuerySpecification<DictionaryType>(request.PageCondition, request.FilterGroup);
        var page = await queryRepository.GetPageAsync<DictionaryTypeOutDto>(spec, cancellationToken);
        logger.LogInformation("获取字典类型分页列表，页码：{Page}，页大小：{PageSize}，结果数：{Count}，总数：{Total}",
            request.PageCondition.PageIndex, request.PageCondition.PageSize, page.Data.Length, page.Total);
        return page;
    }
}
